﻿using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Sidvall.IdentityManager.UI.Entities
{
	public partial class PluginCollection
	{
		#region Public Members

		#region ClearCustomFields

		public void ClearCustomFields()
		{
			foreach (var item in this)
				item.ClearCustomFields();
		}

		#endregion
		#region ImportCustomFields

		public void ImportCustomFields(PluginCollection items)
		{
			if (items == null)
				return;
			foreach (var serverItem in this)
			{
				if (serverItem.PluginId == null)
					continue;
				var item = (from o in items
							where o.PluginId == serverItem.PluginId
							select o).FirstOrDefault();
				serverItem.ImportCustomFields(item);
			}
		}

		#endregion
		#region InitializeAsync

		public async Task InitializeAsync()
		{
			var tasks = new List<Task>();
			foreach (var item in this)
				tasks.Add(item.InitializeAsync());
			await Task.WhenAll(tasks);
		}

		#endregion

		#endregion
	}
}